<template>
	<page-meta :page-style="themeColor"></page-meta>
	<view>
		<block v-if="diyData">
			<block v-for="(item, index) in diyData.value" :key="index">
				<view v-if="item.componentName == 'GoodsCategory' && isShowComp ">
					<diy-category @tologin="toLogin" ref="category" :value="item" :category_id="category_id"></diy-category>
				</view>
			</block>
		</block>

		<ns-login ref="login"></ns-login>

		<loading-cover ref="loadingCover"></loading-cover>

		<!-- #ifdef MP-WEIXIN -->
		<!-- 小程序隐私协议 -->
		<privacy-popup ref="privacyPopup"></privacy-popup>
		<!-- #endif -->

		<!-- 底部tabBar -->
		<view id="tab-bar">
			<diy-bottom-nav></diy-bottom-nav>
		</view>
    
  
	</view>
</template>

<script>
  import uniPopupA from '@/components/uni-popup/uni-popup.vue';
	export default {
		components: {
			uniPopupA
		},
		data() {
			return {
        qrcode: false,
				diyData: null,
				category_id:0,//xiaolu
        isShowComp: false
			};
		},
		onLoad(options) {
			// lx 弹出会员
      // this.openDialog()
			console.log('cccccccddddd')
			uni.setStorageSync('category_id',0); //xiaolu
			this.category_id = options.category_id || 0 ;//xiaolu
			uni.hideTabBar();
			this.getDiyInfo();
        console.log(this.$refs.category)
		},
    onHide() {
      this.isShowComp = false
		
    },
		onShow() {
			//xiaolu start
			uni.setStorageSync('addressDefault',false); //xiaolu
			if(uni.getStorageSync('category_id'))	
			{
				this.category_id = uni.getStorageSync('category_id')
			}
			//xiaolu end
			if (this.$refs.category) this.$refs.category[0].pageShow();
      this.$nextTick(() => {
        this.isShowComp = true
      })
		},
		onUnload() {
			if (!this.storeToken && this.$refs.login) this.$refs.login.cancelCompleteInfo();
		},
		methods: {
      // openQrCode() {
      //   this.qrcode = !this.qrcode
      // },
      // openDialog(){
      //   this.$refs.popup.open() 
      // },
			getDiyInfo() {
				this.$api.sendRequest({
					url: '/api/diyview/info',
					data: {
						name: 'DIY_VIEW_GOODS_CATEGORY'
					},
					success: res => {
						if (res.code == 0 && res.data) {
							this.diyData = res.data;
							if (this.diyData.value) {
								this.diyData = JSON.parse(this.diyData.value);
								if (this.$refs.loadingCover) this.$refs.loadingCover.hide();
							}
							uni.stopPullDownRefresh();
						}
					}
				});
			},
			toLogin() {
				this.$refs.login.open('/pages/goods/category')
			}
		},
		onPullDownRefresh() {
			uni.hideTabBar();
			this.getDiyInfo();
		}
	};
</script>

<style lang="scss">
  // lx
  .vip-msg {
    padding: 10px;
    background-color: white;
    display: flex;
    flex-direction: column;
    text-align: center;
    
    .title {
      margin-bottom: 10px;
      font-size: 14px;
    }
    
    .content {
      background-color: #efefef;
      display: flex;
      flex-direction: row;
      justify-content: space-around;
      border-radius: 3px;
      padding: 10px 0px;
      width: 18rem;
      
      .left {
        color: #ffc112;
      }
    }
    
    .vip-pay {
      background-color: aliceblue;
      margin: 5px 0px;
      padding: 5px 0px;
      border-radius: 3px;
    }
  }
  
  
	/deep/ .uni-popup__wrapper.uni-center {
		background: rgba(0, 0, 0, 0.6);
	}

	/deep/ .uni-popup__wrapper-box {
		border-radius: 0 !important;
	}

	/deep/ .uni-popup__wrapper.uni-custom.center .uni-popup__wrapper-box {
		overflow-y: visible;
	}

	/deep/ .loading-layer {
		background: #fff !important;
	}

	// 分类四一级展开
	/deep/ .category-template-4 .template-four .uni-popup__wrapper-box {
		border-radius: 0px 0px 14px 14px !important;
		overflow: hidden;
	}

	/deep/ .category-template-4 .content-wrap .categoty-goods-wrap .goods-list {
		margin-top: 30rpx;
	}

	/deep/ .category-template-4 .content-wrap .goods-list .goods-item .footer-wrap .right-wrap .num-action {
		width: 46rpx;
		height: 46rpx;
	}

	/deep/ .uni-page-refresh-inner .uni-page-refresh__path {
		stroke: rgb(1, 1, 1) !important;
	}
</style>